Chapter 2 Electricity profiles
This chapter provides electricity profiles and a R coding technique. Electricity profiles are illustrated to give an insight into profile behavior. R coding technique are given in order to understand the process flow and manage the big data obtained from several sources in the organization.
2.1 Initial settings
Before the project starts, packages are required as follows:
- A
tidyversepackage is a bunch of packages to handle with a data analysis (for more information click here). It consists of data manipulation and visualization as follows:- A
ggplot2package is for data visualization. - A
dplyrpackage is for data manipulation. - A
tidyrpackage is for data tidying. - A
readrpackage is for data import. - A
purrrpackage is for functional programming. - A
tibblepackage is a modern reimagining of the data.frame. - A
stringrpackage is for strings. - A
forcatspackage is for factors. - A
lubridatepackage is for date and time.
- A
- A
readxlpackage is used for read data from Excel into R. - A
scalespackage is applied to scale plots in the ggplot2 package. - A
gluepackage interprets strings literal. The package embeds R expressions and inserts into argument string. - A
knitrpackage is a lightweight API’s designed to give users full control of the output without heavy coding work. In this project, the package is used for making a HTML.
library(tidyverse) #For data manipulation
library(readxl) #For reading the excel sheet
library(scales)
library(glue)
library(knitr)
library(plotly)Theme and lines for figures are set in a variable named Themeline as follows:
theme_bw()function provides a black and white theme.theme()function applied for setting theme and line represented in plots.linepalette1andlinepalette1variables set line colors.
ThemeLine <-
theme_bw() +
theme(
panel.border=element_rect(fill=NA),
panel.grid.minor = element_line(color = NA),
# axis.title=element_text(size=5),
# axis.text.x = element_text(hjust=1,size = 10, angle = 0),
axis.line=element_line(colour="black"),
panel.background=element_rect(fill = "white"),
panel.grid.major.x=element_line(linetype="dashed",colour="grey",linewidth = 0.5),
panel.grid.major.y = element_blank(),
# panel.grid.major=element_blank(),
strip.background=element_rect(fill="white", colour="white"),
strip.text.x = element_text(size=10, colour = "black", angle = 0,face="bold"),
axis.text.x=element_text(size = 10,angle=45, vjust=0.9, hjust=1, margin = unit(c(t = 0.3, r = 0, b = 0, l = 0), "cm")),
axis.text.y=element_text(size = 10,margin = unit(c(t = 0, r = 0.3, b = 0, l = 0), "cm")),
legend.text = element_text(size = 10),
legend.title = element_text(size = 10),
axis.ticks.length=unit(-0.15,"cm")
)
linepalette1 <- c("#4DAF4A","#FF7F00","#377EB8","#E41A1C","#984EA3","#F781BF","#8DD3C7","#FB8072","#80B1D3","#FDB462","#B3DE69","#FCCDE5","#D9D9D9","#BC80BD","#CCEBC5","#FFED6F","#7f878f","#A65628","#FFFF33")
linepalette2 <- c("#E41A1C","#FF7F00","#377EB8","#B3DE69","#4DAF4A","#984EA3","#F781BF","#8DD3C7","#FB8072","#80B1D3","#FDB462","#FCCDE5","#D9D9D9","#BC80BD","#CCEBC5","#FFED6F","#7f878f","#A65628","#FFFF33")Lists are create to store variables.
2.2 The EGAT electrity sale profiles
2.2.1 The 2019 MEA EGAT sale profile
The electricity sale profile from EGAT is given by the Power System Control and Operation Division (ฝ่ายควบคุมระบบกำลังไฟฟ้า).
#----- The 2019 MEA EGAT sale profile ----####
# Profile data ####
profile <-
read_excel("raw_data/raw_data_profiles/02_Hourly Sale_NetGen_2019.xlsx",
sheet = "Load Curve",
range = "C3:D17523"
) %>%
select(datetime = `Date/Time`, MEA) %>%
mutate(date = date(datetime),
time = format(as.POSIXct(datetime),"%H:%M:%S"),
year = year(datetime),
month = month(datetime),
day = day(datetime)) %>%
select(datetime, date, time, year, month, day, MEA)| datetime | date | time | year | month | day | MEA |
|---|---|---|---|---|---|---|
| 2019-01-01 00:00:00 | 2019-01-01 | 00:00:00 | 2019 | 1 | 1 | 3361.083 |
| 2019-01-01 00:30:00 | 2019-01-01 | 00:30:00 | 2019 | 1 | 1 | 3244.405 |
| 2019-01-01 01:00:00 | 2019-01-01 | 01:00:00 | 2019 | 1 | 1 | 3199.672 |
| 2019-01-01 01:30:00 | 2019-01-01 | 01:30:00 | 2019 | 1 | 1 | 3153.101 |
| 2019-01-01 02:00:00 | 2019-01-01 | 02:00:00 | 2019 | 1 | 1 | 3085.642 |
The peak, minimun in the unit of MW, and an electricity sale to MEA in GWh from the profile are calculated. The electricity sale to MEA (in GWh) is calculated by the summation of profile in MW divided by 2000.
The reason to divide by 2,000 is that the profile is given a time stamp in every 30-min. There are 17,520 values. Therefore, the profile is divided by 2 to get the results in every 1 hr.. We divided the output by 1,000 to convert the unit from MWh to GWh (see equation (2.1)).
\[\begin{equation} Ene_{t}=\frac{\sum_{i=1}^{17520} (profile_{t,i})}{2*1000} \tag{2.1} \end{equation}\]
Where, \(Ene_{t}\) denotes an calculated energy (electricity) in year \(t\).
\(profile_{t,i}\) denotes a generation in the unit of MW in year \(t\) at a time stamp \(i\).
\(i\) denotes a time stamp in a 30-minute interval. Therefore, there are 17,520 intervals in a year (8,760 hrs.).
# Summary data ####
maxv <- ceiling(max(profile$MEA)) # Get a peak MW
minv <- floor(min(profile$MEA)) # Get a min MW
energy <- sum(profile$MEA)/2000 # Calculate the energyThe peak and minimum MW days are also needed to assess in order to provide the maximum and minimum a saled electricity from EGAT to MEA.
peak_day <- profile %>% #Find a peak day
group_by(year) %>%
filter(MEA == max(MEA)) %>%
pull(datetime)
min_day <- profile %>% #Find a peak day
group_by(year) %>%
filter(MEA == min(MEA)) %>%
pull(datetime)Load factor is calculated by the energy in equation (2.1) divided a maximum energy. A maximum energy is the peak multiplied by 8760 hours. Result is presented in a percentage.
\[\begin{equation} LF_{t}=\frac{Energy_{t}}{Peak_{d,h} * 8760}*100 \tag{2.2} \end{equation}\]
Where, \(LF_{t}\) denotes the load factor at year \(t\) in percentage.
\(Energy_{t}\) denotes the calculated energy from equation (2.1) at year \(t\) in GWh.
\(Peak_{d,h}\) denotes the peak electricity sale on the date \(d\) at time \(h\).
Create a table to store relevant data.
summary <- tibble(peak_day = peak_day,
min_day = min_day,
peak_mw = maxv,
min_mw = minv,
energy_gwh = energy,
load_factor = load_factor) # combine all data in 1 tableIn 2019, the electricity sale to MEA by EGAT reached it peak 9,526 MW on 2019-04-25 14:00:00. The energy (electricity) sale to MEA was 54,939.73 GWh. The summary of the electricity sale to MEA by EGAT in 2019 is given in Table 2.2.
| peak_day | min_day | peak_mw | min_mw | energy_gwh | load_factor |
|---|---|---|---|---|---|
| 2019-04-25 14:00:00 | 2019-01-01 05:00:00 | 9526 | 2748 | 54939.73 | 65.84% |
The 2019 electricity sale profile from EGAT to MEA is illustrated (see Figure 2.1).
profile_plot <-
ggplot() +
geom_line(data=profile,
aes(x = datetime,
y = MEA,
group = month,
color = as.factor(month)),
show.legend = FALSE) +
ThemeLine +
labs(x = NULL,
y = "EGAT sale to MEA (MW)")+
scale_x_datetime(breaks=date_breaks("1 month"),
labels=date_format("%b %y")) +
scale_y_continuous(breaks = seq(0, round(maxv,-3),1000),
limits = c(0, round(maxv, -3))) +
scale_color_manual(values = linepalette1) +
geom_point(data=summary,
aes(x = peak_day, y = peak_mw))+
geom_text(data = summary,
aes(x = peak_day, y = round(maxv, -3)),
label = glue("Peak {maxv} MW \n@ {peak_day}"))+
geom_point(data=summary,
aes(x = min_day, y = min_mw))+
geom_text(data = summary,
aes(x = min_day, y = round(minv, -3)),
label = glue("Minimum {minv} MW \n@ {min_day}"),
hjust = 0,
vjust = 1.5)Figure 2.1: EGAT electricity sale profile to MEA in 2019.
Outputs are saved. Outputs are listed as follows:
- Create a file name
mea_egtsle_2019.png - Save a plot in a directory using
ggsave()function - Save profile data in a
profiledatalist - Save figures in a
profilefigurelist - Save summary data in a
summarydatalist
outputfigure <- paste0(outfigdir, "mea_egtsle_2019.png")
ggsave(profile_plot, file = outputfigure, dpi = 150, width = 15, height = 5, units = "in", limitsize = FALSE)
profiledata <- c(profiledata, list("mea_egtsle_2019" = profile))
profilefigure <- c(profilefigure, list("mea_egtsle_2019" = profile_plot))
summarydata <- c(summarydata, list("sum_mea_egtsle_2019" = summary))2.2.2 The 2019 PEA-R1 (Central region) EGAT sale profile
Read a profile data
profile <-
read_excel("raw_data/raw_data_profiles/02_Hourly Sale_NetGen_2019.xlsx",
sheet = "Load Curve",
range = "C3:E17523"
) %>%
select(datetime = `Date/Time`, PEA_R1) %>%
mutate(date = date(datetime),
time = format(as.POSIXct(datetime),"%H:%M:%S"),
year = year(datetime),
month = month(datetime),
day = day(datetime)) %>%
select(datetime, date, time, year, month, day, PEA_R1)| datetime | date | time | year | month | day | PEA_R1 |
|---|---|---|---|---|---|---|
| 2019-01-01 00:00:00 | 2019-01-01 | 00:00:00 | 2019 | 1 | 1 | 5036.982 |
| 2019-01-01 00:30:00 | 2019-01-01 | 00:30:00 | 2019 | 1 | 1 | 4907.355 |
| 2019-01-01 01:00:00 | 2019-01-01 | 01:00:00 | 2019 | 1 | 1 | 4929.126 |
| 2019-01-01 01:30:00 | 2019-01-01 | 01:30:00 | 2019 | 1 | 1 | 4793.341 |
| 2019-01-01 02:00:00 | 2019-01-01 | 02:00:00 | 2019 | 1 | 1 | 4789.811 |
maxv <- ceiling(max(profile$PEA_R1)) # Get a peak MW
minv <- floor(min(profile$PEA_R1)) # Get a min MW
energy <- sum(profile$PEA_R1)/2000 # Calculate the energy
peak_day <- profile %>% #Find a peak day
group_by(year) %>%
filter(PEA_R1 == max(PEA_R1)) %>%
pull(datetime)
min_day <- profile %>% #Find a peak day
group_by(year) %>%
filter(PEA_R1 == min(PEA_R1)) %>%
pull(datetime)
load_factor <- percent((energy*10^3)/(maxv*8760),
accuracy = 0.01,
decimal.mark = ".")
summary <- tibble(peak_day = peak_day,
min_day = min_day,
peak_mw = maxv,
min_mw = minv,
energy_gwh = energy,
load_factor = load_factor) | peak_day | min_day | peak_mw | min_mw | energy_gwh | load_factor |
|---|---|---|---|---|---|
| 2019-05-03 23:00:00 | 2019-01-01 12:00:00 | 11936 | 3293 | 80961.36 | 77.43% |
The 2019 electricity sale profile from EGAT to PEA-R1 is illustrated (see Figure 2.2).
profile_plot <-
ggplot() +
geom_line(data=profile,
aes(x = datetime,
y = PEA_R1,
group = month,
color = as.factor(month)),
show.legend = FALSE) +
ThemeLine +
labs(x = NULL,
y = "EGAT sale to PEA R1 (Central region) (MW)")+
scale_x_datetime(breaks=date_breaks("1 month"),
labels=date_format("%b %y")) +
scale_y_continuous(breaks = seq(0, round(maxv,-3),1000),
limits = c(0, round(maxv, -3))) +
scale_color_manual(values = linepalette1) +
geom_point(data=summary,
aes(x = peak_day, y = peak_mw))+
geom_text(data = summary,
aes(x = peak_day, y = round(maxv, -3)),
label = glue("Peak {maxv} MW \n@ {peak_day}"))+
geom_point(data=summary,
aes(x = min_day, y = min_mw))+
geom_text(data = summary,
aes(x = min_day, y = round(minv, -3)),
label = glue("Minimum {minv} MW \n@ {min_day}"),
hjust = 0,
vjust = 1.5)Figure 2.2: EGAT electricity sale profile to PEA-R1 in 2019.
outputfigure <- paste0(outfigdir, "pea_r1_central_egtsle_2019.png")
ggsave(profile_plot, file = outputfigure, dpi = 150, width = 15, height = 5, units = "in", limitsize = FALSE)
profiledata <- c(profiledata, list("pea_r1_central_egtsle_2019" = profile))
profilefigure <- c(profilefigure, list("pea_r1_central_egtsle_2019" = profile_plot))
summarydata <- c(summarydata, list("sum_pea_r1_central_egtsle_2019" = summary))2.2.3 The 2019 PEA-R2 (North Eastern region) EGAT sale profile
# Profile data ####
profile <-
read_excel("raw_data/raw_data_profiles/02_Hourly Sale_NetGen_2019.xlsx",
sheet = "Load Curve",
range = "C3:F17523"
) %>%
select(datetime = `Date/Time`, PEA_R2) %>%
mutate(date = date(datetime),
time = format(as.POSIXct(datetime),"%H:%M:%S"),
year = year(datetime),
month = month(datetime),
day = day(datetime)) %>%
select(datetime, date, time, year, month, day, PEA_R2) #%>%
# mutate(strdatetime = as.factor(strptime(glue("{year}-{month}-{day} {time}"), "%Y-%m-%d %H:%M:%S")))| datetime | date | time | year | month | day | PEA_R2 |
|---|---|---|---|---|---|---|
| 2019-01-01 00:00:00 | 2019-01-01 | 00:00:00 | 2019 | 1 | 1 | 1459.520 |
| 2019-01-01 00:30:00 | 2019-01-01 | 00:30:00 | 2019 | 1 | 1 | 1415.846 |
| 2019-01-01 01:00:00 | 2019-01-01 | 01:00:00 | 2019 | 1 | 1 | 1350.192 |
| 2019-01-01 01:30:00 | 2019-01-01 | 01:30:00 | 2019 | 1 | 1 | 1287.925 |
| 2019-01-01 02:00:00 | 2019-01-01 | 02:00:00 | 2019 | 1 | 1 | 1231.863 |
# Summary data ####
maxv <- ceiling(max(profile$PEA_R2)) # Get a peak MW
minv <- floor(min(profile$PEA_R2)) # Get a min MW
energy <- sum(profile$PEA_R2)/2000 # Calculate the energy
peak_day <- profile %>% #Find a peak day
group_by(year) %>%
filter(PEA_R2 == max(PEA_R2)) %>%
pull(datetime)
min_day <- profile %>% #Find a peak day
group_by(year) %>%
filter(PEA_R2 == min(PEA_R2)) %>%
pull(datetime)
load_factor <- percent((energy*10^3)/(maxv*8760),
accuracy = 0.01,
decimal.mark = ".")
summary <- tibble(peak_day = peak_day,
min_day = min_day,
peak_mw = maxv,
min_mw = minv,
energy_gwh = energy,
load_factor = load_factor) # combine all data in 1 table| peak_day | min_day | peak_mw | min_mw | energy_gwh | load_factor |
|---|---|---|---|---|---|
| 2019-04-20 21:00:00 | 2019-01-01 12:00:00 | 3803 | 970 | 20007.86 | 60.06% |
# Plot a profile ####
profile_plot <-
ggplot() +
geom_line(data=profile,
aes(x = datetime,
y = PEA_R2,
group = month,
color = as.factor(month)),
show.legend = FALSE) +
ThemeLine +
labs(x = NULL,
y = "EGAT sale to PEA R2 (North Eastern region) (MW)")+
scale_x_datetime(breaks=date_breaks("1 month"),
labels=date_format("%b %y")) +
scale_y_continuous(breaks = seq(0, round(maxv,-3),1000),
limits = c(0, round(maxv, -3))) +
scale_color_manual(values = linepalette1) +
geom_point(data=summary,
aes(x = peak_day, y = peak_mw))+
geom_text(data = summary,
aes(x = peak_day, y = round(maxv, -3)),
label = glue("Peak {maxv} MW \n@ {peak_day}"))+
geom_point(data=summary,
aes(x = min_day, y = min_mw))+
geom_text(data = summary,
aes(x = min_day, y = round(minv, -3)),
label = glue("Minimum {minv} MW \n@ {min_day}"),
hjust = 0,
vjust = 1.5)
# Save the output ####
outputfigure <- paste0(outfigdir, "pea_r2_northeastern_egtsle_2019.png")
ggsave(profile_plot, file = outputfigure, dpi = 150, width = 15, height = 5, units = "in", limitsize = FALSE)
profiledata <- c(profiledata, list("pea_r2_northeastern_egtsle_2019" = profile))
profilefigure <- c(profilefigure, list("pea_r2_northeastern_egtsle_2019" = profile_plot))
summarydata <- c(summarydata, list("sum_pea_r2_northeastern_egtsle_2019" = summary))The 2019 electricity sale profile from EGAT to PEA-R2 is illustrated in Figure 2.3).
Figure 2.3: EGAT electricity sale profile to PEA-R2 in 2019.